local M={}

function M:Awake()
    self.is=self.GameObject:GetComponent(Alice.ImageSprite)
    self.time=0
    self.current=0
    self.v=0
    self.y=0
    self.isDead=false
    self.EffectAS=Alice.GameObject.Find("MainCamera"):GetComponent(Alice.AudioSource)
    self.as=self.GameObject:GetComponent(Alice.AudioSource)
end

function M:Fly()
    if not self.isDead then
        self.v=150
        self.as:Stop()
        self.as:Play()
    end
end

function M:GEffect(delta)
    if not self.isDead then
        self.v=self.v-9.8*30*delta
        self.y=self.y+self.v*delta
        self.GameObject:SetPosition(0,self.y,0)
    end
end

function M:Update(delta)
    self.time=self.time+delta
    if self.time>=0.33 then
        self.time=self.time-0.33
        self.current=self.current+1
        self.current=self.current%3
        self.is:SetTexture("Images/bird0_"..tostring(self.current)..".png")
    end
    self:GEffect(delta)
end

function M:OnCollideBegin(other)
    local props=other:GetScript("TestBed.props")
    if props.score == -1 then
        self.isDead=true
        self.EffectAS:SetAudioClip("A/sfx_hit.mp3")
        self.EffectAS:Stop();
        self.EffectAS:Play();
        stop=true
        Alice.GameObject.Find("GameOverUI"):Show()
        Alice.Console.Debug(self.GameObject:GetName(),"game over",other:GetName())
    elseif props.score==1 then
        self.EffectAS:SetAudioClip("A/sfx_point.mp3")
        self.EffectAS:Stop();
        self.EffectAS:Play();
        Alice.Console.Debug("get 1 point",other:GetName())
    end
end

return M